// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// This file is based on code available under the Apache license here:
//   https://github.com/apache/incubator-doris/blob/master/gensrc/proto/descriptors.proto

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

syntax="proto2";

package starrocks;
option java_package = "com.starrocks.proto";

import "types.proto";
import "tablet_schema.proto";

message PSlotDescriptor {
    required int32 id = 1;
    required int32 parent = 2; // tuple id which this slot is belong to
    required PTypeDesc slot_type = 3;
    required int32 column_pos = 4;   // in originating table
    required int32 byte_offset = 5;  // into tuple
    required int32 null_indicator_byte = 6;
    required int32 null_indicator_bit = 7;
    required string col_name = 8;
    required int32 slot_idx = 9;
    required bool is_materialized = 10;
    repeated string global_dict_words = 11; 
    optional int64 global_dict_version = 12;
};

message PTupleDescriptor {
    required int32 id = 1;
    required int32 byte_size = 2;
    required int32 num_null_bytes = 3;
    optional int64 table_id = 4;
    optional int32 num_null_slots = 5;
};

message POlapTableColumnParam {
    repeated ColumnPB columns_desc = 1;
    repeated int32 sort_key_uid = 2;
    required int32 short_key_column_count = 3;
};

message POlapTableIndexSchema {
    required int64 id = 1;
    repeated string columns = 2;
    required int32 schema_hash = 3;
    optional POlapTableColumnParam column_param = 4;
    optional int64 schema_id = 5;
};

message POlapTableSchemaParam {
    required int64 db_id = 1;
    required int64 table_id = 2;
    required int64 version = 3;

    // Logical columns, contain all column that in logical table
    repeated PSlotDescriptor slot_descs = 4;
    required PTupleDescriptor tuple_desc = 5;
    repeated POlapTableIndexSchema indexes = 6;
};

